<?php
    class Pages extends MY_Controller {

        public $keywords=NULL;
        public $data = array();
        public function __construct() {
            parent::__construct();
            $this->data['categories']=  $this->categories_model->get_categories();
            $this->data['top_news']=  $this->news_model->get_news(NULL,FALSE);
           
        }
        public function index() {
            $data = array_merge($this->data, array(
                'title' => 'Phú Vương Triều',
                'products'=>   $this->products_model->get_products(),
                'controller'=>   $this->router->fetch_class(),
                'action' =>      $this->router->fetch_method()
            ));
            $this->load->view('templates/layout', $data);        
        }
        public function info(){
            $data = array_merge($this->data, array(
                'title' => 'Phú Vương Triều',
                'controller'=>   $this->router->fetch_class(),
                'action' =>      $this->router->fetch_method()
            ));
            $this->load->view('templates/layout', $data);   
            
        }
        public function news(){
        $this->load->model('news_model');
        $this->load->library('pagination');
            $segments=$this->uri->total_segments();
            $array_segments=array();
            for($i=3; $i<=$segments; $i=$i+2){
                $array_segments[$this->uri->segment($i)]= $this->uri->segment($i+1) ? $this->uri->segment($i+1):0;
            }
            if(!empty($_POST['categories']))
                $array_segments['categories']=$_POST['categories'];
            if(empty($array_segments['page']))
                $array_segments['page']=0;
            $url_segment=$this->my_utilities->set_url_segment($array_segments);
        $data = array_merge($this->data, array(
                'title' => 'news',
                'news'=>   $this->news_model->get_news($array_segments,FALSE),
                'array_segment' =>$array_segments,
                'url_segment' =>$url_segment,
                'total'=>   $this->news_model->get_news($array_segments,TRUE),
                'controller'=>   $this->router->fetch_class(),
                'action' =>      $this->router->fetch_method()
            ));
            $this->load->view('templates/layout', $data);
        }
        public  function detail_news($name){
            $this->load->model('news_model');
            $id = $this->my_utilities->get_id_from_uri($name);
            $var = array(
                'id'    =>  $id
            );
          $data = array_merge($this->data, array(
                'title' => 'Detail_news',
                'news'=>   $this->news_model->get_where_news($var),
                'controller'=>   $this->router->fetch_class(),
                'action' =>      $this->router->fetch_method()
            ));
            $this->load->view('templates/layout', $data);   
        }
        public function contact(){
            
        }
        public function report_price(){
            
        }
        public function products_categories($name){
         $id_type = $this->my_utilities->get_id_from_uri($name);
         $var = array(
                'type'    =>  $id_type,
                'name'=>$this->categories_model->get_category_where(array('id'=>$id_type)),
         );
         $data = array_merge($this->data, array(
                'title' => 'Detail_categories',
                'is_categories' => $var['name'],
                'products'=>   $this->products_model->get_where_products(array(key($var)=>  reset($var))),
                'controller'=>   $this->router->fetch_class(),
                'action' =>      $this->router->fetch_method()
            ));
            $this->load->view('templates/layout', $data);        
            
        }
        public function detail_products($name){
            $id = $this->my_utilities->get_id_from_uri($name);
            $var = array(
                'id'    =>  $id
            );
          $data = array_merge($this->data, array(
                'title' => 'Detail_products',
                'products'=>   $this->products_model->get_where_products($var),
                'controller'=>   $this->router->fetch_class(),
                'action' =>      $this->router->fetch_method()
            ));
            $this->load->view('templates/layout', $data);     
        }
        
       
}